public class Text {

    public static void swap(int[] array, int pos){
        for (int i = pos; i < array.length-1; i++) {
            array[pos] = array[pos+1];
        }
    }

    public static int removeDuplicates(int[] nums) {
        int solt = 0;
        int fost = 1;
        while (fost< nums.length) {
            if(nums[solt] != nums[fost]){
                nums[solt+1] = nums[fost];
                solt++;
            }
            fost++;
        }
        return solt+1;
    }

    public static void main(String[] args) {
        int[] array = {1,2,2,3};
        System.out.println(removeDuplicates(array));
        for(int i : array){
            System.out.print(i+" ");
        }
    }

    //给你一个数组 nums 和一个值 val，你需要 原地 移除所有数值等于 val 的元素。元素的顺序可能发生改变。然后返回 nums 中与 val 不同的元素的数量。
    public static int removeElement(int[] nums, int val) {
        int j = nums.length-1;
        for (int i = 0; i < j; i++) {
            if(nums[i] == val){
                int tmp = nums[i];
                nums[i] = nums[j];
                nums[j] = tmp;
                j--;
                i--;
            }
        }
        return j+1;
    }

    public static void main3(String[] args) {
        int[] array = {3,2,2,3};

        int i = removeElement(array,3);
        System.out.println(i);
        for(int j : array){
            System.out.print(j+" ");
        }
    }

    public static void main1(String[] args) {


        List list = new MyArrayList();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
//        System.out.println(list.isFull());
        list.display();
        list.add(1,199);
        list.add(1,999);
        list.display();
        System.out.println("========");
        System.out.println(list.contains(0));
        System.out.println(list.indexOf(199));
        System.out.println(list.get(1));
        System.out.println();
        list.set(1,1000);
        list.display();
        list.remove(1000);
        list.display();
        list.clear();
        list.display();


    }
}
